package com.zp.qualitypractice.mvp4;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;

import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
import com.zp.qualitypractice.App;
import com.zp.qualitypractice.mvp3.*;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by izp on 2017/7/5.
 */

public abstract class BaseActivity<T extends MVPBase.BasePresenter> extends RxAppCompatActivity implements MVPBase.BaseView{
    private Unbinder unbinder;
    T mPresenter;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        setContentView(setContentLayout());
        App.getApp().getAppManager().addActivity(this);
        unbinder = ButterKnife.bind(this);
        if (null!=mPresenter){
            mPresenter = createPresenter();
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        App.getApp().getAppManager().popCurrentActivity();
        if (null!=unbinder){
            unbinder.unbind();
        }
        if (null!=mPresenter){
            mPresenter.detachView();
        }
    }
    protected abstract @LayoutRes int setContentLayout();
}
